package com.rj.controller;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public class TestJson {
	
	public String getJsonFromOtherPage(String urlPath) {
		StringBuffer buString = null;
		try {
			//"http://m.weather.com.cn/data/101230101.html"
			URL url = new URL(urlPath);
			InputStream in = url.openStream();
			InputStreamReader inputSR = new InputStreamReader(in, "UTF-8");
			buString = new StringBuffer();
			char[] buffer = new char[4096];
			int bytes_read = 0;

			while ((bytes_read = inputSR.read(buffer)) != -1) {
				String ss = new String(buffer, 0, bytes_read);
				buString.append(ss);
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return buString.toString();
	}
	
	public static void main(String[] args) {
		// http://61.4.185.48:81/g/
		TestJson TestJson = new TestJson();
		String urlPath = "http://61.4.185.48:81/g/";
		String areaCode = TestJson.getJsonFromOtherPage(urlPath);
		System.out.println("areaCode="+areaCode);
		
		int beginIndex = areaCode.indexOf("id=");
		int endIndex = areaCode.indexOf(";if");
		String str = areaCode.substring(beginIndex, endIndex);
		System.out.println("realAreaCode = " + str);
		
	}
}
